package Rangel.firebrigade.buildingdetector.idbased;

import Rangel.firebrigade.buildingdetector.FireBrigadeTarget;
import Rangel.firebrigade.world.RangelFireBrigadeWorld;
import rescuecore2.standard.entities.FireBrigade;
import rescuecore2.worldmodel.EntityID;

public class IdBasedExploreLeaderSelector implements IExploreLeaderSelector {
    public IdBasedExploreLeaderSelector(RangelFireBrigadeWorld world) {
        this.world = world;
    }

    private RangelFireBrigadeWorld world;

    @Override
    public EntityID findLeader(FireBrigadeTarget fireBrigadeTarget) {
        EntityID smallestId = null;

        if (world.getDistance(world.getAgentInfo().getID(),fireBrigadeTarget.getRangelBuilding().getID()) > world.getMaxExtinguishDistance()) {
            return smallestId;
        }

        for (FireBrigade next : world.getFireBrigadesSeen()) {
            if (smallestId == null || smallestId.getValue() < next.getID().getValue()) {
                smallestId = next.getID();
            }
        }

        return smallestId;
    }
}
